//
//  BHFunListInfoModel.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/8/10.
//

import UIKit

class BHFunListInfoModel {
    var venueName: String = ""
    var cityName: String = ""
    var distance: String = "" // 距离; 用户未授权  为null
    var areaName: String = ""
    var typeOneLabel: String = "" // 一级运动类型label
    var typeTwoLabel: String = "" // 二级运动类型label
    var price: String = ""
    var name: String = ""
    var funId: String = ""
    var beginTime: String = ""

    var createFlag: Int = 0 // 是否是创建人 0：否 1：是
    
    
    func parseDic(_ dic: [String:Any]) {
        self.venueName = BHJsonTool.decodeStringFromDic(dic: dic, key: "venueName")
        self.cityName = BHJsonTool.decodeStringFromDic(dic: dic, key: "cityName")
        self.distance = BHJsonTool.decodeStringFromDic(dic: dic, key: "distance")
        self.areaName = BHJsonTool.decodeStringFromDic(dic: dic, key: "areaName")
        self.typeOneLabel = BHJsonTool.decodeStringFromDic(dic: dic, key: "typeOneLabel")
        self.typeTwoLabel = BHJsonTool.decodeStringFromDic(dic: dic, key: "typeTwoLabel")
        self.price = BHJsonTool.decodeStringFromDic(dic: dic, key: "price")
        self.name = BHJsonTool.decodeStringFromDic(dic: dic, key: "name")
        self.funId = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.beginTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "beginTime")

        self.createFlag = BHJsonTool.decodeIntFromDic(dic: dic, key: "createFlag")
        if self.createFlag == -1 {
            self.createFlag = 0
        }
    }
    
    lazy var showDistance: String = {
        if self.distance.isEmpty == true {
            return ""
        }else {
            let array = self.distance.components(separatedBy: ".")
            let meter = array.first ?? "0"
            if meter.count > 2 {
                let showMeter = (Double(meter) ?? 0)/1000.0
                return "\(showMeter)km"
            }else {
                return "\(meter)m"
            }
        }
    }()

    
}
